package com.is.add.service.impl;

import com.is.add.event.LogApi;
import com.is.add.mapper.ApiLogMapper;
import com.is.add.mapper.AyduserMapper;
import com.is.add.model.ApiLog;
import com.is.add.model.Ayduser;
import com.is.add.service.IApiLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author: zhou
 * @Description:
 * @Date:Create in 2019/07/01
 * @Modified By:
 */
@Service
public class ApiLogServiceImpl implements IApiLogService {

    @Autowired
    private ApiLogMapper apiLogMapper;

    @Autowired
    private AyduserMapper ayduserMapper;

    @Override
    public void saveApiLog(LogApi logApi) {
        //logapi ==> apilog（持久化）
        ApiLog apiLog = new ApiLog();
        apiLog.setCreateId(logApi.getCreateBy());
        Integer u = Integer.parseInt(logApi.getCreateBy());
        Ayduser ayduser = ayduserMapper.selectByPrimaryKey(u);
        apiLog.setCreateName(ayduser.getUsername());
        apiLog.setRemoteIp(logApi.getRemoteIp());
        apiLog.setTime(new Date());
        apiLog.setRequestUri(logApi.getRequestUri());
        apiLog.setType(logApi.getType());
        apiLog.setTitle(logApi.getTitle());
        apiLogMapper.saveApiLog(apiLog);
    }
}
